var t = getApp(),
    e = t.requirejs("core");
Page({
    data: {
        list: [],
        own_level: {},
        member: {},
        show: true,
        bgColor: 'linear-gradient(to right, #ecbe85 0%, #ecbe85 100%)',
        backgroundImage: '',
        buttonColor:'',
        fontColorAssistant: '#be2521',
        fontColorHost: '#fff',
        fontColorGuest:'',
        fontColorOrder:''

    },
    onLoad: function (op) {
        // console.log("load");
        var that = this
        var userinfo = wx.getStorageSync('userinfo')
        var leves = wx.getStorageSync('leves')
        that.setData({
            userinfo: userinfo,
            leves: leves
        })
        e.get("commission/index", {}, ((e) => {
            that.setData({
                member: e
            })
            // console.log(e,'这是门店吗')
        }))
        e.post("goods.yyindex", {}, ((e) => {
            that.setData({
                list: e.list
            })
        }))
        e.post("goods.djts", {}, ((e) => {
            that.setData({
                own_level: e.own_level
            })
        }))
    },
    onShow: function () {
        e.post('member/withdraw',{},money_=>{
            this.setData({
                money:money_.credit
            })
        })
        var that = this
        var userinfo = wx.getStorageSync('userinfo')
        var leves = wx.getStorageSync('leves')
        that.setData({
            userinfo: userinfo,
            leves: leves
        })
        if (that.data.leves == false && userinfo == false) {
            that.setData({
                show: false
            })
            wx.showModal({
                cancelColor: 'cancelColor',
                content: "还未登录请去登录",
                showCancel: false,
                success(res) {
                    if (res.confirm) {
                        wx.redirectTo({
                            url: '/pages/auth/index',
                        })
                    }
                }
            })
        } else if (leves.level > 2) {
            that.onLoad()
            that.setData({
                show: true
            })
        } 
        // else if (leves.level <= 2 || leves.discount == 10) {
          else if (leves.discount == 10) {
            // console.log(leves.level,'level')
            that.setData({
                show: false
            })
            wx.showModal({
                cancelColor: 'cancelColor',
                content: "仅对创客以上的会员开放",
                showCancel: false,
                success(res) {
                    if (res.confirm) {
                        wx.switchTab({
                            url: '/pages/member/index/index',
                        })
                    }
                }
            })
        }
        this.getSysset()
    },
    getSysset() {
        var that = this
        e.post("index.get_sysset", {
            syssetType: 1
        }, ((e) => {
            let data = e.data
            if (data.backgroundImage) {
                that.data.backgroundImage = 'https://zzsl.sctqmt.com/attachment/' + data.backgroundImage
            } else {
                that.data.backgroundImage = ''
            }
            that.setData({
                buttonColor: data.buttonColor,
                fontColorAssistant: data.fontcolorAssistant,
                backgroundImage: that.data.backgroundImage,
                fontColorHost:data.fontColorHost,
                fontColorGuest:data.fontColorGuest,
                fontColorOrder:data.fontcolororder,
            });
            // console.log(data.fontcolorAssistant,'副颜色')
            // console.log(data, '配置颜色', that.data)
        }))
    },
    getleves() {
        var that = this
        e.post("goods.djts", {}, ((e) => {
            that.setData({
                own_level: e.own_level
            })
            wx.setStorageSync('leves', that.data.own_level)
        }))
    },
    onUnload: function () {
        // wx.switchTab({
        //     url: '/pages/index/index',
        // })
    },

    // getData: function () {
    //     var t = this;
    //     e.get("commission/index", {}, function (e) {
    //         7e4 != e.error ? (e.show = !0, t.setData(e), wx.setNavigationBarTitle({
    //                 title: e.set.texts.center
    //             })) :
    //             wx.switchTab({
    //                 url: "/pages/operation/index"
    //             });
    //             // wx.redirectTo({
    //             //     url: "../../commission/pages/register/index"
    //             // });
    //     });
    // },

});